import { createRouter, createWebHistory } from 'vue-router'
import {
  ChatDotRound,
  Document,
  Folder,
  Calendar
  // 导入Element Plus图标组件（如果使用）
} from '@element-plus/icons-vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: () => import('@/views/Manager.vue'),
      redirect: '/home',
      children: [
        { path: 'person', component: () => import('@/views/manager/Person.vue') },
        { path: 'tPerson', component:  () => import('@/views/manager/TPerson.vue') },
        { path: 'sPerson', component:  () => import('@/views/manager/SPerson.vue') },
        { path: 'password', component:  () => import('@/views/manager/Password.vue') },
        { path: 'home', component:  () => import('@/views/manager/Home.vue') },
        { path: 'admin', component:  () => import('@/views/manager/Admin.vue') },
        { path: 'teacher', component:  () => import('@/views/manager/Teacher.vue') },
        { path: 'student', component:  () => import('@/views/manager/Student.vue') },
        { path: 'notice', component:  () => import('@/views/manager/Notice.vue') },
        { path: 'college', component:  () => import('@/views/manager/College.vue') },
        { path: 'speciality', component:  () => import('@/views/manager/Speciality.vue') },
        { path: 'course', component:  () => import('@/views/manager/Course.vue') },
        { path: 'choice', component:  () => import('@/views/manager/Choice.vue') },
        { path: 'work', component:  () => import('@/views/manager/Work.vue') },
        { path: 'myCourse', component:  () => import('@/views/manager/MyCourse.vue') },
        { path: 'myTeach', component:  () => import('@/views/manager/MyTeach.vue') },
        {
          path: 'courseDetail/:id',
          name: 'CourseDetail',
          component: () => import('@/views/manager/CourseDetail.vue'),
          props: true,
          redirect: { name: 'AiAssistant' }, // 默认重定向到AI助教
          children: [
            {
              path: 'ai',
              name: 'AiAssistant',
              component: () => import('@/views/manager/components/AiAssistant.vue'),
              meta: {
                title: 'AI助教',
                icon: ChatDotRound // 使用Element Plus图标
              }
            },
            {
              path: 'chapters',
              name: 'Chapters',
              component: () => import('@/views/manager/components/Chapters.vue'),
              meta: {
                title: '课程章节',
                icon: Document
              }
            },
            {
              path: 'materials',
              name: 'Materials',
              component: () => import('@/views/manager/components/Materials.vue'),
              meta: {
                title: '课程资料',
                icon: Folder
              }
            },
            {
              path: 'qna',
              name: 'QnA',
              component: () => import('@/views/manager/components/QnA.vue'),
              meta: {
                title: '问答讨论',
                icon: 'question' // 使用Element Plus内置图标名称
              }
            },
            {
              path: 'checkin',
              name: 'CheckIn',
              component: () => import('@/views/manager/components/CheckIn.vue'),
              meta: {
                title: '签到记录',
                icon: 'check'
              }
            },
            {
              path: 'discussion',
              name: 'Discussion',
              component: () => import('@/views/manager/components/Discussion.vue'),
              meta: {
                title: '课程讨论',
                icon: 'chat-dot-round'
              } } ] } ]
    },

    {
      path: '/login',
      name: 'Login',
      component: () => import('@/views/Login.vue'),
      meta: {
        title: '登录'
      }
    },
    {
      path: '/register',
      name: 'Register',
      component: () => import('@/views/Register.vue'),
      meta: {
        title: '注册'
      }
    },
    {
      path: '/:pathMatch(.*)',
      name: 'NotFound',
      component: () => import('@/views/NotFound.vue'),
      meta: {
        title: '页面不存在'
      }
    }
  ]
})

// 路由导航守卫（可选）
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = `${to.meta.title} - 教学管理系统`
  }
  next()
})

export default router